package com.eshidai.simple_springboot.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.eshidai.simple_springboot.bean.Email;
import com.eshidai.simple_springboot.bean.MsgSend;
import com.eshidai.simple_springboot.common.EmailMsgSend;
import com.eshidai.simple_springboot.service.MsgSendService;
import com.eshidai.simple_springboot.task.AsyncTask;

@RestController
@RequestMapping(value="/msg")
public class MsgSendController {
	public static final Logger LOG = LoggerFactory.getLogger(MsgSendController.class);
	
	@Autowired
	public AsyncTask asyncTask;
	
	@Autowired
	public MsgSendService msgSendService;
	
	@RequestMapping(value="/add")
	public String create(@RequestParam String msgId ) {
		MsgSend msg = new MsgSend();
		msg.setMsgId(msgId);
		msg.setMsgType(2);
		msg.setSendTime("2017-03-31 15:01:01");
		
		msgSendService.create(msg);
		return "sucess";
	}
	
	@RequestMapping(value="/async")
	public String async(@RequestParam String msgId ) {
		asyncTask.doTask();
		
		return "sucess";
	}
	
	@RequestMapping(value="/upd")
	public String upd(@RequestParam String msgId ) {
		
		msgSendService.updateByMsgId(msgId);
		return "sucess";
	}
	
	@RequestMapping(value="/sdmail")
	public void sendEmail() {
		Email email = new Email();
		email.setSender("hy024231@163.com");
		email.setReceiver("yinghuang12@qq.com");
		email.setContent("内容：我是一个");
		email.setTopic("主题：我是用boot发的");
		
		msgSendService.sendSimpleMail(email);
	}
}
